package com.example.scancodelogindemo.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Data
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String redisHost;

    @Value("${spring.redis.port}")
    private Integer redisPort;

    @Value("${spring.redis.password}")
    private String password;

    @Value("${spring.redis.database}")
    private Integer database;

    @Bean
    public RedissonClient redisClient() {
        Config config = new Config();
        String redisAddress = String.format("redis://%s:%s", redisHost, redisPort);
        config.useSingleServer().setAddress(redisAddress).setDatabase(database).setPassword(password);
        return Redisson.create(config);
    }

}
